/**
 * 对企业微信发送给企业后台的消息加解密示例代码.
 * 
 * @copyright Copyright (c) 1998-2014 Tencent Inc.
 */

// ------------------------------------------------------------------------

package com.beta.auth.utils.aes;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * SHA1 class
 *
 * 计算消息签名接口.
 */
public class SHA1 {
	private SHA1(){}


	/**
	 * @Comment SHA1实现
	 * @Author Ron
	 * @Date 2017年9月13日 下午3:30:36
	 * @return
	 */
	public static String shaEncode(String inStr) throws NoSuchAlgorithmException {
		MessageDigest sha = MessageDigest.getInstance("SHA-1");
		byte[] byteArray = inStr.getBytes(StandardCharsets.UTF_8);
		byte[] md5Bytes = sha.digest(byteArray);
		StringBuilder hexValue = new StringBuilder();
		for (int i = 0; i < md5Bytes.length; i++) {
			int val = (md5Bytes[i]) & 0xff;
			if (val < 16) {
				hexValue.append("0");
			}
			hexValue.append(Integer.toHexString(val));
		}
		return hexValue.toString();

	}
}



